<?php

namespace app\controllers;

use yii\web\Controller;
use app\models\UploadForm;
use yii\web\UploadedFile;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of UploadController
 * 文件上传控制器
 * 主要用于上传Excel表格，将Excel内容存入数据库
 *
 * @author liaochangwang
 * 
 */
class UploadController extends Controller {

    //put your code here
    public $layout = 'main_1';
    public function actionUpload() {
        $model = new UploadForm();

        if (\Yii::$app->request->isPost) {
            $model->file = UploadedFile::getInstance($model, 'file');

            if ($model->file && $model->validate()) {
                $model->file->saveAs('uploads/' . $model->file->baseName . '.' . $model->file->extension);
            }
        }

        return $this->render('upload', ['model' => $model]);
    }

}
